package persistence;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;


final public class Periodical {
	public int id=0;
	@Size(min=1,max=100, message="Title too long or too short!")
	@NotNull
	public String title;
	@NotNull
	public String publisher;
	public String issn;
	public PredefinedEntry publicationInterval;
	public String acNo;
	public PredefinedEntry kindOfPublication;
	public PredefinedEntry kindOfOnlineAccess;
	public String onlineAccessCredentials;
	public String eissn;
	public String webAddress;
	public Boolean inEZB;
	public Boolean inHAN;
	public String notes;
	
	/** the constructors are protected, so that only the DAO may instantiate
	 *  the Entity, thus ensuring, that every entity returned by the DAO
	 *  actually exists in the DB
	 */
	
	protected Periodical(){}
	
	protected Periodical (int id) {
		setId(id);
	}
	
	protected Periodical(int id, String title, String publisher, String issn,
			PredefinedEntry publicationInterval, String acNo, PredefinedEntry kindOfPublication, 
			PredefinedEntry kindOfOnlineAccess, String onlineAccessCredentials, String eissn,
			String webAddress, Boolean inEZB, Boolean inHAN, String notes) {
		this.setId(id);
		this.title = title;
		this.publisher = publisher;
		this.issn = issn;
		this.publicationInterval = publicationInterval;
		this.acNo = acNo;
		this.kindOfPublication = kindOfPublication;
		this.kindOfOnlineAccess = kindOfOnlineAccess;
		this.onlineAccessCredentials = onlineAccessCredentials;
		this.eissn = eissn;
		this.webAddress = webAddress;
		this.inEZB = inEZB;
		this.inHAN = inHAN;
		this.notes = notes;		
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Periodical other = (Periodical) obj;
		if (id != other.id)
			return false;
		return true;
	}

//	@Override
//	public boolean equals(Object obj) {
//		if (obj==null || obj.getClass()!=this.getClass()) {
//			return false;
//		}
//		Periodical compObj = (Periodical) obj;
//		return compObj.getId()==this.id &&
//				compObj.getTitle().equals(this.title) &&
//				compObj.getPublisher().equals(this.publisher);
//	}
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Periodical: id=").append(id).append(", title=").append(title).
		append(", publisher=").append(publisher).append(", issn=").append(issn).
		append(", publicationInterval=").append(publicationInterval).append(", acNo=").append(acNo).
		append(", kindOfPublication=").append(kindOfPublication).append(", kindOfOnlineAccess=").append(kindOfOnlineAccess).
		append(", onlineAccessCredentials=").append(onlineAccessCredentials).append(", eissn=").append(eissn).
		append(", webAddress=").append(webAddress).append(", in EZB=").append(inEZB).append(", inHAN=").append(inHAN).
		append(", notes=").append(notes);
		
		return builder.toString();
	}

	public int getId() {
		return id;
	}

	public String getTitle() {
		return title;
	}
	public String getPublisher() {
		return publisher;
	}
	public String getIssn() {
		return issn;
	}
	public PredefinedEntry getPublicationInterval() {
		return publicationInterval;
	}
	public String getAcNo() {
		return acNo;
	}
	public PredefinedEntry getKindOfPublication() {
		return kindOfPublication;
	}
	public PredefinedEntry getKindOfOnlineAccess() {
		return kindOfOnlineAccess;
	}
	public String getOnlineAccessCredentials() {
		return onlineAccessCredentials;
	}
	public String getEissn() {
		return eissn;
	}
	public String getWebAddress() {
		return webAddress;
	}
	public Boolean isInEZB() {
		return inEZB;
	}
	public Boolean isInHAN() {
		return inHAN;
	}
	public String getNotes() {
		return notes;
	}
	public void setId(int id) {
		this.id = id;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}
	public void setIssn(String issn) {
		this.issn = issn;
	}
	public void setPulicationInterval(PredefinedEntry publicationInterval) {
		this.publicationInterval = publicationInterval;
	}
	public void setAcNo(String acNo) {
		this.acNo = acNo;
	}
	public void setKindOfPublication(PredefinedEntry kindOfPublication) {
		this.kindOfPublication = kindOfPublication;
	}
	public void setKindOfOnlineAccess(PredefinedEntry kindOfOnlineAccess) {
		this.kindOfOnlineAccess = kindOfOnlineAccess;
	}
	public void setOnlineAccessCredentials(String onlineAccessCredentials) {
		this.onlineAccessCredentials = onlineAccessCredentials;
	}
	public void setEiisn(String eiisn) {
		this.eissn = eiisn;
	}
	public void setWebAddress(String webAddress) {
		this.webAddress = webAddress;
	}
	public void setInEZB(Boolean inEZB) {
		this.inEZB = inEZB;
	}
	public void setInHAN(Boolean inHAN) {
		this.inHAN = inHAN;
	}
	public void setNotes(String notes) {
		this.notes = notes;
	}	
}
